import Vue from 'vue'
import * as Util from '../../components/Util'

let BillService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.BillService = Vue.prototype.$BillService = BillService
  },

  // 重新分配
  replaceDistribution (model, row) {
    let data = {
      newbill: {
        f_start_number: model.f_start_number,
        f_end_number: model.f_end_number,
        f_number: model.f_number,
        f_bill_id: model.f_start_number,
        f_bill_number: model.f_bill_number,
        f_bill_type: model.f_bill_type[0],
        f_user: model.f_user[0],
        f_operator: model.f_operator[0],
        f_filiale: Util.f.f_fengongsi,
        f_outlets: Util.f.f_parentname,
        f_bill_state: '停用'
      }
    }
    if (row && row.id) {
      data.oldbill = {
        id: row.id,
        f_end_number: model.f_start_number - 1,
        f_number: model.f_start_number - row.f_start_number + 1
      }
    } else {
      data.oldbill = null
    }
    return Vue.post('rs/logic/billDistribution', {data: data}, {resolveMsg: null, rejectMsg: '分配失败'})
  },
  updateNumber (data) {
    return Vue.resetpost('rs/entity/t_billcollec', data, {resolveMsg: '修改票号成功', rejectMsg: '修改票号失败'})
  },
  changeBillState (data) {
    return Vue.post('rs/logic/changeBillState', {data: data}, {resolveMsg: null, rejectMsg: '修改发票状态失败'})
  },
  modifyState (row, type) {
    let data = {
      id: row.id,
      f_user: row.f_user,
      f_bill_type: row.f_bill_type
    }
    if (type === 'startup') {
      data.f_bill_state = '启用'
      return Vue.resetpost('rs/logic/modifyState', {data: data}, {resolveMsg: `${data.f_bill_state}成功`, rejectMsg: '修改状态失败'})
    } else if (type === 'breakoff') {
      data.f_bill_state = '停用'
    } else if (type === 'nullify') {
      data.f_bill_state = '作废'
    }
    return Vue.resetpost('rs/entity/t_billcollec', data, {resolveMsg: `${data.f_bill_state}成功`, rejectMsg: '修改状态失败'})
  },
  stopBill (data) {
    return Vue.resetpost('rs/entity/t_billcollec', data, {resolveMsg: null, rejectMsg: null})
  }
}

export default BillService
